/**
 * Created by Administrator on 16-8-30.
 */
angular.module('myApp',[])
.factory('Data',function(){
    return[
        {
            title:'no1',
            content:'no1-content'
        },
        {
            title:'no2',
            content:'no2-content'
        },
        {
            title:'no3',
            content:'no3-content'
        }
    ]
})
.controller('firstConstroller',['$scope','Data',function($scope,Data){
    $scope.data=Data;
}])

    .directive('fjpGroup',function(){
        return{
            restrict:'E',
            replace:true,
            template:'<div class="panel-group" ng-transclude >',
            transclude:true,
            controllerAs:'grCtrl',
            controller:function(){
              this.groups=[];
                this.closeOtherCollapse=function(nowScope){
                    angular.forEach(this.groups, function (scope) {
                        if(scope!==nowScope){
                            scope.isOpen=false;
                        }
                    })
                }
            }
        }
    })
    .directive('fjpCollapse',function(){
        return{
            restrict:'E',
            replace:true,
            require:'^fjpGroup',
            templateUrl:'Public/tmp/fjpCollapse.html',
            scope:{
                heading:'@'
            },

            link:function(scope,element,attrs,grCtrl){
                scope.isOpen=true;
                scope.changeOpen=function(){
                    scope.isOpen=!scope.isOpen;

                    grCtrl.closeOtherCollapse(scope);
                }
                grCtrl.groups.push(scope);
            },
            transclude:true
        }
    })
